package cn.quevo.core.exception;

import java.util.ArrayList;
import java.util.List;

import cn.quevo.core.enums.ResultStatusEnum;
import cn.quevo.core.lang.StringUtils;
import lombok.Getter;
import lombok.Setter;

/**
 * 全部参数检验异常
 *
 * @author July july_sky@foxmail.com
 * @date 2018-03-09 14:05:04
 * @Copyright ©2015-2035 湘豫(北京)科技有限公司. All Rights Reserved.
 * @version 1.0
 * @return
 */
@Getter
@Setter
public class CheckParamsAllException extends CustomException {

    /**
     * 
     */
    private static final long serialVersionUID = 6414303885328955361L;

    private List<CheckParamsException> exceptions = new ArrayList<>();

    public CheckParamsAllException() {
        this(null);
    }

    public CheckParamsAllException(List<CheckParamsException> exceptions) {
        super(ResultStatusEnum.PARAMS_INCOMPLETE);
        this.exceptions = exceptions;
    }

    /**
     * 新增异常信息
     *
     * @author July july_sky@foxmail.com
     * @date 2018-03-09 14:11:09
     * @Copyright ©2015-2035 湘豫(北京)科技有限公司. All Rights Reserved.
     * @version 1.0
     * @param exception
     * @return
     */
    public CheckParamsAllException addException(CheckParamsException exception) {
        this.exceptions.add(exception);
        return this;
    }

    @Override
    public String toString() {
        if (StringUtils.isEmpty(exceptions)) {
            return super.toString();
        }
        StringBuilder msgs = new StringBuilder();
        for (CheckParamsException exception : exceptions) {
            msgs.append(exception.toString()).append("\t\n");
        }
        return msgs.toString();
    }
}
